﻿var XmlManager = function (xDoc) {
    var initXmlMnanger = (function (_x) {
        var xmlDoc;
        try //Internet Explorer
            {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";
            xmlDoc.loadXML(_x);
        }
        catch (e) {
            try //Firefox, Mozilla, Opera, etc.
               {
                parser = new DOMParser();
                xmlDoc = parser.parseFromString(_x, "text/xml");
            }
            catch (e) {
                if (Object.prototype.hasOwnProperty.call(window, "log")) {
                    log.error(e.description);
                }
                else {
                    console.log("error:" + e.description);
                }
            }
        }
        return xmlDoc;
    })(xDoc);

    var xmlObj = $(initXmlMnanger.xml);

    this.getSubValue = function (tagName) {
        return xmlObj.find(tagName).text();
    }

    this.getSubValues = function (parentName, nodeName, tagName) {
        var result = [];
        xmlObj.find(parentName).find(nodeName).each(function (i, n) {
            result.push = $(n).attr(tagName);
        });
        return result;
    }

    this.setSubValue = function (val) {
        xmlObj.find(tagName).val(val);
    }
};